/**
 ***************************************(C) COPYRIGHT 2019 USTC***************************************
 * @file       remote_UART.h
 * @brief      this file contains the common defines and functions prototypes for 
 *             the remote_UART.c driver
 * @note         
 * @Version    V1.0.0
 * @Date           
 ***************************************(C) COPYRIGHT 2019 USTC***************************************
 */

#ifndef __BSP_UART_H__
#define __BSP_UART_H__

#include "string.h"
#include "stdlib.h"
#include "usart.h"
#include "math.h"
#include "SPI_bus.h"
#include "CAN_bus.h"

#define UART_RX_DMA_SIZE (1024)
#define DBUS_MAX_LEN (50)
#define DBUS_BUFLEN (18)
#define DBUS_HUART huart1 /* for dji remote controler reciever */

/* ----------------------- RC Switch Definition----------------------------- */
#define RC_SW_UP ((uint16_t)1)
#define RC_SW_MID ((uint16_t)3)
#define RC_SW_DOWN ((uint16_t)2)
/* ----------------------- PC Key Definition-------------------------------- */
#define KEY_PRESSED_OFFSET_W ((uint16_t)0x01 << 0)
#define KEY_PRESSED_OFFSET_S ((uint16_t)0x01 << 1)
#define KEY_PRESSED_OFFSET_A ((uint16_t)0x01 << 2)
#define KEY_PRESSED_OFFSET_D ((uint16_t)0x01 << 3)
#define KEY_PRESSED_OFFSET_SHIFT ((uint16_t)0x01 << 4)
#define KEY_PRESSED_OFFSET_CTRL ((uint16_t)0x01 << 5)
#define KEY_PRESSED_OFFSET_Q ((uint16_t)0x01 << 6)
#define KEY_PRESSED_OFFSET_E ((uint16_t)0x01 << 7)
#define KEY_PRESSED_OFFSET_R ((uint16_t)0x01 << 8)
#define KEY_PRESSED_OFFSET_F ((uint16_t)0x01 << 9)
#define KEY_PRESSED_OFFSET_G ((uint16_t)0x01 << 10)
#define KEY_PRESSED_OFFSET_Z ((uint16_t)0x01 << 11)
#define KEY_PRESSED_OFFSET_X ((uint16_t)0x01 << 12)
#define KEY_PRESSED_OFFSET_C ((uint16_t)0x01 << 13)
#define KEY_PRESSED_OFFSET_V ((uint16_t)0x01 << 14)
#define KEY_PRESSED_OFFSET_B ((uint16_t)0x01 << 15)

/** 
  * @brief  remote control information
  */

typedef struct RCControlTypeDef
{
	int16_t rc_ch0;
	int16_t rc_ch1;
	int16_t rc_ch2;
	int16_t rc_ch3;
	uint8_t rc_s1;
	uint8_t rc_s2;

	int16_t mouse_x;
	int16_t mouse_y;
	int16_t mouse_z;
	uint8_t mouse_press_l;
	uint8_t mouse_press_r;

	uint16_t key_v;
	int16_t yaw;
} RCControlTypeDef;

extern volatile RCControlTypeDef RC_DATA;
extern uint8_t dbus_buf[];
void uart_receive_handler(UART_HandleTypeDef *huart);
void Dbus_UART_Init(void);
void USART_SendData(USART_TypeDef *USARTx, uint16_t Data);
void rc_callback_handler(uint8_t *buff);
void KeyBoard_Control(int16_t omega, int16_t vtx, int16_t vty);
void Remote_Control(int16_t omega, int16_t vtx, int16_t vty);
#endif
